package cn.dmp.tags

import org.apache.commons.lang.StringUtils
import org.apache.spark.sql.Row


// 3
/**
  * 设备和地域打标
  * 设备：设备操作系统、设备联网方式 、设备运营商方式
  * 地域标签（省标签格式：ZPxxx->1, 地市标签格式: ZCxxx->1）xxx 为省或市名称
  */
object Tags4_Devices extends Tags {
  /**
    * 打标签的方法定义。参数是可变的，返回一个Map[String, Int]类型的
    *
    * @param args
    * @return
    */
  override def makeTags(args: Any*): Map[String, Int] = {

    var map = Map[String, Int]()
    val row: Row = args(0).asInstanceOf[Row]

    // 设备
    val client = row.getAs[Int]("Client")
    val decives = row.getAs[String]("Device")
    val ntm = row.getAs[String]("Networkmannername")
    val ispname = row.getAs[String]("Ispname")

    client match {
      case 1 => map += (("D00010001",1))
      case 2 => map += (("D00010002",1))
      case 3 => map += (("D00010003",1))
      case _ => map += (("D00010004",1))
    }

    if (StringUtils.isNotEmpty(decives))
      map += (("DN"+decives, 1))

    ntm.toUpperCase match {
      case "WIFI" => map += (("D00020001", 1))
      case "4G" => map += (("D00020002", 1))
      case "3G" => map += (("D00020003", 1))
      case "2G" => map += (("D00020004", 1))
      case _ => map += (("D00020005", 1))
    }

    ispname match {
      case "移动" => map += (("D00030001", 1))
      case "联通" => map += (("D00030002", 1))
      case "电信" => map += (("D00030003", 1))
      case _ => map += (("D00030004", 1))
    }


    // 地域标签（省标签格式：ZPxxx->1, 地市标签格式: ZCxxx->1）xxx 为省或市名称
    val pName: String = row.getAs[String]("Provincename")
    val cName: String = row.getAs[String]("Cityname")
    if (StringUtils.isNotEmpty(pName))
      map += (("ZP"+pName, 1))
    if (StringUtils.isNotEmpty(cName))
      map += (("ZC"+cName, 1))

    map

  }
}
